<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <hello-vue :cart-list="cartList" :title="title"></hello-vue>
      <main-content :list="list"></main-content>
      <footer-bar></footer-bar>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
      Vue.component('hello-vue', {
        props: ['title', 'cartList'],
        watch: {
          cartList(v) {
            console.log('v:', v)
          },
        },
        mounted() {
          console.log(this.cartList, 'cartlist')
        },
        template: `<h1>{{title}}</h1>`,
      })

      Vue.component('main-content', {
        props: ['list'],
        template: `
         <ul>
           <li v-for="item in list">{{item}}</li> 
         </ul>
        `,
      })

      Vue.component('footer-bar', {
        template: `
         <h1>footerBar</h1>
        `,
      })

      const vm = new Vue({
        el: '#app',
        data() {
          return {
            title: 'Hello Vue!',
            list: [1, 2, 3, 4, 5, 6],
            cartList: [],
          }
        },
        async created() {
          const response = await axios.get('./data.json')
          this.cartList = response.data
          console.log(this.cartList, 'this.cartList')
        },
      })
    </script>
  </body>
</html>
